﻿//
// *************************************************************************************
// WP-Framework
// 
// Developed by
// Lukas Kretschmar (lkretschmar.dev@bluewin.ch)
//
// Switzerland, Copyright (c) 2013 lkretschmar
// This content is released under the MIT License (http://opensource.org/licenses/MIT).
//     
// *************************************************************************************
//
//
			

using System;

namespace KretschIT.WP_Fx.Core.Converters
{
    public class Try
    {
        public static bool Cast<TIn, TOut>(TIn value, out TOut result, Func<TIn, TOut> convert)
        {
            try
            {
                result = convert(value);
                return true;
            }
            catch
            {
                result = default(TOut);
                return false;
            }
        }

        public static TOut Cast<TIn, TOut>(TIn value, Func<TIn, TOut> convert)
        {
            TOut result;
            Cast<TIn, TOut>(value, out result, convert);
            return result;
        }
    }
}
